<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"github.com","root":"/","scheme":"Gemini","version":"7.7.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="git命令快查">
<meta property="og:type" content="article">
<meta property="og:title" content="git笔记">
<meta property="og:url" content="https://github.com/13850554413/13850554413.github.io/2018/10/07/git%E7%AE%80%E8%AE%B0/index.html">
<meta property="og:site_name" content="天上人间">
<meta property="og:description" content="git命令快查">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-10-07T07:30:16.000Z">
<meta property="article:modified_time" content="2020-02-18T12:41:48.039Z">
<meta property="article:author" content="小灰灰">
<meta property="article:tag" content="git">
<meta property="article:tag" content="命令">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://github.com/13850554413/13850554413.github.io/2018/10/07/git%E7%AE%80%E8%AE%B0/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>git笔记 | 天上人间</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">天上人间</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">个人博客| 学习交流| 日志心态</p>
  </div>

  <div class="site-nav-right"></div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://github.com/13850554413/13850554413.github.io/2018/10/07/git%E7%AE%80%E8%AE%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="小灰灰">
      <meta itemprop="description" content="我的博客用于记录">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="天上人间">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          git笔记
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-10-07 15:30:16" itemprop="dateCreated datePublished" datetime="2018-10-07T15:30:16+08:00">2018-10-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-02-18 20:41:48" itemprop="dateModified" datetime="2020-02-18T20:41:48+08:00">2020-02-18</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index">
                    <span itemprop="name">笔记</span>
                  </a>
                </span>
            </span>

          
            <div class="post-description">git命令快查</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><strong>创建仓库和提交</strong></p>
<pre><code>git init 把这个目录变成git可以管理的目录
git add 添加到仓库
git commit -m 提交到仓库
git status 查看仓库当前的状态
git diff 查看文件的变化</code></pre><p><strong>版本回退</strong></p>
<p>注意：git之所以厉害是因为历史可回退和分支编辑，所以学好分支和版本回退是重中之重</p>
<pre><code>git log 查看提交日志
git reset --hard HEAD^  回退到上一个版本(上上个版本HEAD^^)
git reset --hard &quot;commit id&quot;    可以穿梭回去
git checkout -- &quot;file&quot;  撤销修改/返回上次修改的状态add之前的状态
git rm &quot;file&quot;   删除一个文件
git push -u origin master 第一次推送
git push 推送
git remote add origin &quot;仓库地址&quot;  关联远程仓库
git clone 克隆一个项目</code></pre><p><strong>分支操作</strong></p>
<p>注意：git之所以厉害是因为历史可回退和分支编辑，所以学好分支和版本回退是重中之重</p>
<pre><code>git checout -b &quot;新分支&quot; 创建并切换到新分支
git branch  查看当前分支
git checkout &quot;分支名称&quot; 切换分支
git merge &quot;指定分支&quot;    合并指定分支到当前分支
git branch -d &quot;分支名称&quot;    删除分支
git branch origin --delete dev
git push origin :dev
git log --graph 查看分支合并图</code></pre><p><strong>更新的两种方法</strong></p>
<pre><code>git pull 直接拉取远程分支，简单但是把过程细节都隐藏了，一旦有问题很难找出错的地方
git fetch 从另外一个仓库下载对象和引用
git merge 合并</code></pre><p><strong>远程操作</strong></p>
<pre><code>git clone [url] 克隆／下载
git clone -b &lt;branch&gt; [url] 下载一个分支
git branch --set-upstream-to=origin/develop 关联一个远程分支develop
git remote -v 查看远程仓库信息  
git remote add [name] [url] 添加远程仓库  
git remote remove [name] 删除远程仓库name
git fetch [name] 从name仓库更新同步代码
git fetch -all 更新所有
git merage --no-ff [name]/master 合并到本地代码
git pull origin master 更新并合并自己远程仓库的代码
git push -u 向自己的远程仓库推送刚才同步源仓库后的代码</code></pre><p><strong>标签操作</strong></p>
<pre><code>git tag &lt;tagname&gt;   新建一个标签
git tag -a &lt;tanname&gt; -m &quot;aabbbcc....&quot;   可以指定标签信息
git tag 可以查看所有标签
git push orgin &lt;tagname&gt; 推送一个本地标签
git push orgin --tags 推送全部未推送过的标签
git tag -d &lt;tagname&gt; 删除一个本地标签
git push orgin :refs/tags/&lt;tagname&gt; 删除一个远程标签
注意：删除文件需在执行一次 git rm 不然可能会有奇怪的情况</code></pre>
    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/git/" rel="tag"># git</a>
              <a href="/tags/%E5%91%BD%E4%BB%A4/" rel="tag"># 命令</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/07/05/linux%E7%AE%80%E8%AE%B0/" rel="prev" title="linux笔记">
      <i class="fa fa-chevron-left"></i> linux笔记
    </a></div>
      <div class="post-nav-item">
    <a href="/2018/11/05/%E5%A6%82%E4%BD%95%E8%8E%B7%E5%BE%97linux%E6%BA%90%E7%A0%81/" rel="next" title="如何获得linux源码">
      如何获得linux源码 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">小灰灰</p>
  <div class="site-description" itemprop="description">我的博客用于记录</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">10</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com" rel="noopener" target="_blank">链接1</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com" rel="noopener" target="_blank">链接2</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小灰灰</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
